﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace employee.Controls
{
    public partial class emIdentity : common.controls.baseUserControl
    {
        public emIdentity()
        {
            InitializeComponent();
            idCardIdEd.isToUpperCase = true;
            passportEd.isToUpperCase = true;
            issuranceBookEd.isToUpperCase = true;
            medBookEd.isToUpperCase = true;
            perTaxCodeEd.isToUpperCase = true;
            bankAccNoEd.isToUpperCase = true;
        }

        protected void SetDataSource(BindingSource dataSrc)
        {
            common.BindingLibs.BindObject(idCardIdEd, dataSrc, DataAccess.DataCache.myBaseDS.employee.cardIdColumn.ColumnName);
            common.BindingLibs.BindObject(idCardDateEd, dataSrc, DataAccess.DataCache.myBaseDS.employee.cardDateColumn.ColumnName);
            common.BindingLibs.BindObject(idCardPlaceEd, dataSrc, DataAccess.DataCache.myBaseDS.employee.cardIssuerColumn.ColumnName);

            common.BindingLibs.BindObject(passportEd, dataSrc, DataAccess.DataCache.myBaseDS.employee.passportNoColumn.ColumnName);
            common.BindingLibs.BindObject(passportPlaceEd, dataSrc, DataAccess.DataCache.myBaseDS.employee.passportIssuerColumn.ColumnName);
            common.BindingLibs.BindObject(passportDateEd, dataSrc, DataAccess.DataCache.myBaseDS.employee.passportDateColumn.ColumnName);
            common.BindingLibs.BindObject(passportExpDateEd, dataSrc, DataAccess.DataCache.myBaseDS.employee.passportExpDateColumn.ColumnName);

            common.BindingLibs.BindObject(issuranceBookEd, dataSrc, DataAccess.DataCache.myBaseDS.employee.socialInsuranceNoColumn.ColumnName);
            common.BindingLibs.BindObject(issuranceBookPlaceEd, dataSrc, DataAccess.DataCache.myBaseDS.employee.socialInsurancePlaceColumn.ColumnName);
            
            common.BindingLibs.BindObject(medBookEd, dataSrc, DataAccess.DataCache.myBaseDS.employee.medInsuranceNoColumn.ColumnName);
            common.BindingLibs.BindObject(medBookPlaceEd, dataSrc, DataAccess.DataCache.myBaseDS.employee.medInsurancePlaceColumn.ColumnName);
            
            common.BindingLibs.BindObject(perTaxCodeEd, dataSrc, DataAccess.DataCache.myBaseDS.employee.taxCodeColumn.ColumnName);
            common.BindingLibs.BindObject(perTaxCodeIssuerEd, dataSrc, DataAccess.DataCache.myBaseDS.employee.taxIssuerColumn.ColumnName);

            common.BindingLibs.BindObject(bankAccNoEd, dataSrc, DataAccess.DataCache.myBaseDS.employee.bankAccNoColumn.ColumnName);
            common.BindingLibs.BindObject(bankNameEd, dataSrc, DataAccess.DataCache.myBaseDS.employee.bankNameColumn.ColumnName);
            common.BindingLibs.BindObject(bankBranchEd, dataSrc, DataAccess.DataCache.myBaseDS.employee.bankBranchColumn.ColumnName);

            idCardIdEd.MaxLength = DataAccess.DataCache.myBaseDS.employee.cardIdColumn.MaxLength;
            passportEd.MaxLength = DataAccess.DataCache.myBaseDS.employee.passportNoColumn.MaxLength;
            passportPlaceEd.MaxLength = DataAccess.DataCache.myBaseDS.employee.passportIssuerColumn.MaxLength;

            issuranceBookEd.MaxLength = DataAccess.DataCache.myBaseDS.employee.socialInsuranceNoColumn.MaxLength;
            issuranceBookPlaceEd.MaxLength = DataAccess.DataCache.myBaseDS.employee.socialInsurancePlaceColumn.MaxLength;

            medBookEd.MaxLength = DataAccess.DataCache.myBaseDS.employee.medInsuranceNoColumn.MaxLength;
            medBookPlaceEd.MaxLength = DataAccess.DataCache.myBaseDS.employee.medInsurancePlaceColumn.MaxLength;

            perTaxCodeEd.MaxLength = DataAccess.DataCache.myBaseDS.employee.taxCodeColumn.MaxLength;
            perTaxCodeIssuerEd.MaxLength = DataAccess.DataCache.myBaseDS.employee.taxIssuerColumn.MaxLength;

            bankAccNoEd.MaxLength = DataAccess.DataCache.myBaseDS.employee.bankAccNoColumn.MaxLength;
            bankBranchEd.MaxLength = DataAccess.DataCache.myBaseDS.employee.bankBranchColumn.MaxLength;
            bankNameEd.MaxLength = DataAccess.DataCache.myBaseDS.employee.bankNameColumn.MaxLength;
        }

        public virtual void Init(BindingSource dataSrc)
        {
            passportTypeCb.LoadData();
            SetDataSource(dataSrc);
        }       
        public virtual bool CheckData()
        {
            bool retVal = true;
            ClearNotifyError();
            if (idCardIdEd.Text.Trim() != "")
            {
                if (idCardDateEd.myValue == common.Consts.constNullDate)
                {
                    NotifyError(idCardDateLbl);
                    retVal = false;
                }
                if (idCardPlaceEd.Text.Trim() == "")
                {
                    NotifyError(idCardPlaceLbl);
                    retVal = false;
                }
            }

            if (passportEd.Text.Trim() != "")
            {
                if (passportDateEd.myValue == common.Consts.constNullDate)
                {
                    NotifyError(passportDateLbl);
                    retVal = false;
                }
                if (passportExpDateEd.myValue == common.Consts.constNullDate)
                {
                    NotifyError(passportExpDateLbl);
                    retVal = false;
                }
                if (passportTypeCb.myValue.Trim()  == "")
                {
                    NotifyError(passportTypeLbl);
                    retVal = false;
                }
                if (passportPlaceEd.Text == "")
                {
                    NotifyError(passportPlaceLbl);
                    retVal = false;
                }
            }

            if (issuranceBookEd.Text.Trim() != "")
            {
                if (issuranceBookPlaceEd.Text.Trim()=="")
                {
                    NotifyError(issuranceBookPlaceLbl);
                    retVal = false;
                }
            }

            if (medBookEd.Text.Trim() != "")
            {
                if (medBookPlaceEd.Text.Trim() == "")
                {
                    NotifyError(mediBookPlaceLbl);
                    retVal = false;
                }
            }
            
            if (bankAccNoEd.Text.Trim() != "")
            {
                if (bankNameEd.Text.Trim() == "")
                {
                    NotifyError(bankNameLbl);
                    retVal = false;
                }
                if (bankBranchEd.Text.Trim() == "")
                {
                    NotifyError(bankBranchLbl);
                    retVal = false;
                }
            }

            return retVal;
        }
        public virtual void LockEdit(bool state)
        {
            state = !state;
            idCardIdEd.Enabled = state;
            idCardDateEd.Enabled = state;
            idCardPlaceEd.Enabled = state;

            passportEd.Enabled = state;
            passportTypeCb.Enabled = state;
            passportDateEd.Enabled = state;
            passportExpDateEd.Enabled = state;
            passportPlaceEd.Enabled = state;

            issuranceBookEd.Enabled = state;
            issuranceBookPlaceEd.Enabled = state;

            medBookEd.Enabled = state;
            medBookPlaceEd.Enabled = state;

            perTaxCodeEd.Enabled = state;
            perTaxCodeIssuerEd.Enabled = state;

            bankAccNoEd.Enabled = state;
            bankNameEd.Enabled = state;
            bankBranchEd.Enabled = state;
        }
        public virtual void SetFocus()
        {
            this.Focus();
            idCardIdEd.Focus();
        }
    }
}
